<?php
namespace Act\Os;
use \Lib\ErrorMessage;
use \Lib\Common;
use \Lib\Page;
class Syslog extends Backend{
	private $ADMIN_COMMAND_FOR_LOG=array(	
				'SUCCESS'=>'成功',
				'ERROR'=>'失败',
				'ADD'=>'增加',
				'DELETE'=>'删除',
				'MODIFY'=>'修改',
				'LOGIN'=>'登录',
				'LOGOUT'=>'退出',
				'PAUSE'=>'封停',
				'PLAY'=>'解封',
	);

	private $ADMIN_CLASS_FOR_LOG = array(
			'ALL' => '全部',
			'User'=>'用户',
			'UserGroup'=>'账号组',
			'Module'=>'菜单模块',
			'MenuUrl'=>'功能',
			'GroupRole'=>'权限',
			'QuickNote'=>'QuickNote',
	);
	public function doGet(){
		$_GET['user_name'] = get('user_name','','htmlspecialchars');
		$_GET['class_name'] = get('class_name','','htmlspecialchars');
		$_GET['start_date'] = get('start_date',mktime(0,0,0,date('m')-1),'strtotime');
		$_GET['end_date'] = get('end_date',mktime(0,0,0),'strtotime')+86399;
		extract($_GET);
		$syslog_mod = model('#SysLog','adm_');
		$count = $syslog_mod->searchCount($class_name,$user_name,$start_date,$end_date);
		$page = new Page($count,self::PAGE_SIZE);
		$sys_logs = $syslog_mod->getLogs($class_name,$user_name, $page->offset,$page->size,$start_date,$end_date);

		foreach ($sys_logs as &$log){
			if(array_key_exists($log['action'],$this->ADMIN_COMMAND_FOR_LOG)){
				$log['action']=$this->ADMIN_COMMAND_FOR_LOG[$log['action']];
			}
			 
			$class_obj = $log['class_obj'];
			if(array_key_exists($log['class_name'],$this->ADMIN_CLASS_FOR_LOG)){
				$log['class_name'] = $this->ADMIN_CLASS_FOR_LOG[$log['class_name']];
			}

			
			if($log['class_obj']==""){
				$log['class_obj']='null';
			}

			if(empty($log['result'])){
				$log['result'] = '成功';
			}else{
				$result =json_decode($log['result'],true);
				if(is_array($result)){
					$temp = null;
					foreach($result as $key => $value){
						$temp[] = "$key=>$value";
					}
					$log['result']=implode(';',$temp);
				}else{
					$log['result']=$result;
				}
			}
		}

		$this->display('index.php',array(
			'page_html'=>$page->show(),
			'class_options'=>$this->ADMIN_CLASS_FOR_LOG,
			'sys_logs'=>$sys_logs,
		));
	}
}